
import Foundation

public extension Int {
    
    /// let kbSize: Float = size.kb
    public var kb : Float { return Float(self) / 1_024 }
    /// let mbSize: Float = size.mb
    public var mb : Float { return Float(self) / 1_024 / 1_024 }
    /// let gbSize: Float = size.gb
    public var gb : Float { return Float(self) / 1_024 / 1_024 / 1_024 }
    
}

public extension Double {
    
    public var F: Double { return self } // 华氏温度
    public var C: Double { return (((self - 32.0) * 5.0) / 9.0) } // 摄氏温度
    public var K: Double { return (((self - 32.0) / 1.8) + 273.15) } // 开氏温度
    
}

public extension Array {
    
    /// filter for sort duplicates array
    ///
    /// - Parameter includeElement: block for conditions
    /// - Returns: sorted array
    public func filterDuplicates(_ includeElement: @escaping (_ lhs:Element, _ rhs:Element) -> Bool) -> [Element]{
        var results = [Element]()
        
        forEach { (element) in
            let existingElements = results.filter {
                return includeElement(element, $0)
            }
            if existingElements.count == 0 {
                results.append(element)
            }
        }
        
        return results
    }
}
